# pragma once

# include <QtWidgets/QMainWindow>
# include "ui_MainWindow.h"
# include <vector>
# include <queue>
# include <thread>
# include <atomic>

class ToolBar;
class ShowScreenWindow;
class SettingBar;
class ConnectionWindow;
struct ID3D11Device;
struct ID3D11DeviceContext;
struct ID3D11Texture2D;

class MainWindow : public QMainWindow {
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
	static int runUi(int argc, char* argv[], MainWindow** _window, std::atomic_bool* _ui_state, std::function<void(void)> _callback);

	void log(const QString& _message);
	std::function<const char *(const char *)> onRecordCallback;
	std::function<void(void)> onRecordStopCallbcak;
	std::function<void(int, int*, int*)> onScreenCallback;
	std::function<void(void)> onScreenStopCallback;
	std::function<void(short)> onConnectCallback;
	std::function<void(const QString&)> onMessageInputCallback;
	void frame();
	void copyFromRenderTarget(uint8_t* _buffer, size_t size);
	void videoCaptureToShowWindow(ID3D11Device* _device, ID3D11DeviceContext* _context, ID3D11Texture2D* _monitor_texture);
protected slots:
    void moveMainWindow(QPoint point);
    void changeMain(QString windowName);
	void record();
	void stopRecord();
	void screenWindow(int index);
	void stopScreen();
	void onConnect(short port);
	void onMessageInput(const QString& _message);

protected:

private:
    Ui::MainWindowClass m_ui;
    ToolBar* m_toolbar = nullptr;
	SettingBar* m_settingbar = nullptr;
	bool m_showCursor = true;

	int m_videoCaptureWidth = 0;
	int m_videoCaptureHeight = 0;;

	ShowScreenWindow* m_showWindow = nullptr;
	ConnectionWindow* m_connectionWindow = nullptr;

	void createShowScreenWindow();
	void clearShowScreenWindow();
};
